package com.mcflies.ui.listView;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

import com.mcflies.bean.GroupListViewBean;
import com.mcflies.commons.GroupListViewAdapter;
import com.mcflies.ui.R;

/**
 * @author:mcfly_jun
 * @create_date:2012-8-15
 * @comment:分组ListView学习
 */
public class GroupListViewActivity extends Activity implements
		OnItemClickListener {
	private ListView groupListViewMain_LV;
	private ArrayList<GroupListViewBean> list = new ArrayList<GroupListViewBean>();
	private GroupListViewAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.android_group_list_view_main);
		initWidget();
		initData();

		groupListViewMain_LV.setAdapter(adapter);
		groupListViewMain_LV.setOnItemClickListener(this);
	}

	private void initWidget() {
		groupListViewMain_LV = (ListView) findViewById(R.id.groupListViewMain_LV);
	}

	private void initData() {
		GroupListViewBean bean;
		for (int i = 0; i < 5; i++) {
			if (i == 0) {
				bean = new GroupListViewBean(true, "陈");
				list.add(bean);
			} else {
				bean = new GroupListViewBean(false, "陈俊,编号：" + i);
				list.add(bean);
			}
		}
		for (int i = 0; i < 5; i++) {
			if (i == 0) {
				bean = new GroupListViewBean(true, "吴");
				list.add(bean);
			} else {
				bean = new GroupListViewBean(false, "吴丽,编号：" + i);
				list.add(bean);
			}
		}

		adapter = new GroupListViewAdapter(this, list);
	}

	@Override
	public void onItemClick(AdapterView<?> adapter, View view, int position,
			long id) {
		GroupListViewBean bean = list.get(position);
		Toast.makeText(this, bean.getContent(), Toast.LENGTH_SHORT).show();
	}
}
